<?php

/*
*    Document   : user_image_helper
*   Created on : May 25, 2011, 1:58:32 PM
*    Author     : ClarkT AKA FalleN
*    Company    : Amodity
*    Web        : http://www.amodity.com
*    Copyright  : 2011
*/

/*
	Function: gravatar_link()

	Creates an image link based on Gravatar for the specified email address.
	It will default to the site's generic image if none is found for
	the user.
	
	Note that if gravatar does not have an image that matches the criteria,
	it will return a link to an image under *your_theme/images/user.png*.
	
	Parameters:
		$email	- The email address to check for.
		$size	- The width (and height) of the resulting image to grab.
		$alt	- Alt text to be put in the link tag.
		$title	- The title text to be put in the link tag.
		$class	- Any class(es) that should be assigned to the link tag.
		$id		- The id (if any) that shoudl put in the link tag.
		
	Return:
		The resulting image tag.
 */
function gravatar_link($email=null, $size=48, $alt='', $title='', $class='', $id='') 
{
	// Set our default image based on required size.
	$default_image = base_url().'/assets/images/user.png';
	
	// Set our minimum site rating to PG
	$rating = 'PG';
	
	// Border color 
	$border = 'd6d6d6';
	
	// URL for Gravatar
	$gravatarURL = "http://www.gravatar.com/avatar.php?gravatar_id=%s&default=%s&size=%s&border=%s&rating=%s";
	
	$avatarURL = sprintf
	(
		$gravatarURL, 
		md5($email), 
		$default_image,
		$size,
		$border,
		$rating
	);
	
	return '<img src="'. $avatarURL .'" width="'.	$size .'" height="'. $size . '" alt="'. $alt .'" title="'. $title .'" class="'. $class .'" id="'. $id .'" />';
}


/* End of file user_image_helper */